package cate.game.activity.lostdreamland;

import cate.game.activity.base.core.ActivityGlobalData;
import cate.game.activity.lostdreamland.po.LostDreamlandRecord;
import cate.game.activity.lostdreamland.po.LostDreamlandRecords;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

public class LostDreamlandSPO extends ActivityGlobalData {
    @NoteField(value = "通关记录")
    public Map<Integer, LostDreamlandRecords> recordMap;

    public LostDreamlandSPO() {

    }
    @Override
    public void clear() {
        recordMap.clear();
    }

    @Override
    public void initialize() {
        super.initialize();
        if (recordMap == null) {
            recordMap = new HashMap<>();
        }
    }

    /** 获取指定层的记录(必定能获取到) */
    public LostDreamlandRecord getRecord(int activityId, int day, int level) {
        synchronized (this) {
            LostDreamlandRecords records = recordMap.computeIfAbsent(activityId, k -> new LostDreamlandRecords());
            for (LostDreamlandRecord r : records.recordList) {
                if (r.day == day && r.level == level) {
                    return r;
                }
            }
            LostDreamlandRecord record = new LostDreamlandRecord(day, level);
            records.recordList.add(record);
            return record;
        }
    }
}
